Apps = function(obj){	return Apps.anew(obj);}
Apps.anew = function(obj){this.obj=obj;	return this;}

Apps.header = function(obj){	return Apps.header.anew(obj);}
Apps.header.anew = function(obj){this.obj=obj;	return this;}
Apps.header.ready = function(){
	Apps.search.html();
	Apps.header.msg();
}
Apps.header.msg = function(){
	var data = '<span>推荐使用<a href="http://www.opera.com">Opera</a>,firefox,IE7以上版本访问网站</span>';
	jQuery("#aheader_msg").html(data);
}
/*** search ***/
Apps.search = function(obj){	return Apps.search.anew(obj);}
Apps.search.anew = function(obj){this.obj=obj;	return this;}
Apps.search.html = function(){
	var akey='';
	if(Acan.url.aurl()[0] == 'search'){
		akey = Acan.url.aurl()[2];
	}
	var list = [{"class":"_nav_0 search_nav_bg","value":0,"text":"全站"},{"class":"_nav_1","value":1,"text":"谷歌"},{"class":"_nav_2","value":2,"text":"百度"}];
	var html = Ahtml.tag('div',{"class":"a_search"},
			Ahtml.tag('div',{"class":"_nav"},Apps.search.html_list(list))
			+Ahtml.tag('div',{"class":"_form"},Ahtml.tag('form',{"onsubmit":"return Apps.search.all();"},
				Ahtml.tag('input',{"type":"hidden","class":"_op"})+
				Ahtml.tag('input',{"type":"text","class":"_key","value":akey})+
				Ahtml.tag('input',{"type":"submit","class":"_submit","value":"搜索"})
			))
		);
	jQuery(".-header").append(html);
}
Apps.search.html_list = function(obj){
	var html='';
	for(var i in obj){
		html += Acan.html.tag('div',{"class":obj[i]["class"]},Acan.html.tag('span',{"onmousemove":"Apps.search.bar("+obj[i]["value"]+")"},obj[i]["text"]));
	}
	return html;
}
Apps.search.bar = function(value){
	jQuery(".a_search ._nav div").removeClass("search_nav_bg");
	jQuery(".a_search ._nav_"+value).addClass("search_nav_bg");
	jQuery(".a_search ._op").val(value);
}

Apps.search.all = function(op){
	if(!op){op = jQuery(".a_search ._op").val();}
	if(!op){op = 0;}
	var search = jQuery('.a_search ._key').val();
	var url;
	if (op == 0) {
		url = '/search/all/'+search;
		window.location.href = url;
		return false;
	}else if (op == 1) {
		url = "http://www.google.com.hk/"+"search?domains=abans.cn&sitesearch=abans.cn&client=opera&rls=zh-cn&q="+search+"&sourceid=opera&ie=utf-8&oe=utf-8";
	}else if (op == 2) {
		url = "http://www.baidu.com/"+"s?ct=2097152&si=abans.cn&sts=abans.cn&wd="+search;
	}
	Acan.url.open(url,'Acan_search','scrollbars=yes');
	return false;
}
/*** marquee ***/
var mqs = Array();
Apps.marquee = function(id,way){	return Apps.marquee.anew(id,way);}
Apps.marquee.anew = function(id,way){
	this.mq = Object();
	this.mq.id = id;
	this.mq.speed = 20;
	this.mq.status = '1';
	if(!way) way = 'top';
	this.mq.way = way;
	var mq = jQuery("#"+id);
	var height = mq.height();
	var html = Acan.html.tag('div',{id:id+'1',style:"height:"+height+"px;"},mq.html())+Acan.html.tag('div',{id:id+'2',style:"height:"+height+"px;"});
	mq.html(html);
	this.mq.demo = Acan.get("#"+id);
	this.mq.demo1 = Acan.get("#"+id+'1');
	this.mq.demo2 = Acan.get("#"+id+'2');
	this.mq.demo2.innerHTML = this.mq.demo1.innerHTML;
	return this;
}
Apps.marquee.run = function(){
	var speed = this.mq.speed;
	mqs=setInterval("Apps.marquee.runs()",speed);
	this.mq.demo.onmouseout=function() {mqs=setInterval("Apps.marquee.runs()",speed)}
	this.mq.demo.onmouseover=function() {clearInterval(mqs)}
}
Apps.marquee.runs = function(){
	if(this.mq.way == 'top'){
		if(this.mq.demo2.offsetHeight-this.mq.demo.scrollTop<=0){
			this.mq.demo.scrollTop-=this.mq.demo1.offsetHeight;
		}else{this.mq.demo.scrollTop++;}
	}else if(this.mq.way == 'left'){
		if(this.mq.demo2.offsetWidth-this.mq.demo.scrollLeft<=0){
			this.mq.demo.scrollLeft-=this.mq.demo1.offsetWidth;
		}else{this.mq.demo.scrollLeft++;}
	}
}
//初始化
Apps.form = function(Did,objname,css,columns,url){
	this.Did = Did;
	if(css) this.css = css;
	this.columns = columns;
	this.objname = objname;
	this.url = url;
}
Apps.form.prototype = new Apps.form();
Apps.form.prototype.show = function(title,html,css){
	if(!this.Did){
		this.Did = 'ajax_list';
	}
	if(!obj){
		var obj=Object();
	}
	obj.id=this.Did;
	obj["class"]='acan_win dis_none';
	obj.css={height:'auto',width:'auto'};
	if(css){obj.css=css}
	obj._close={onclick:'Acan.close(\''+obj.id+'\')','class':'-close'};//关闭按钮
	Acan.base.win(obj,title,html);
	//Acan.ajax_bg();
	return jQuery("#"+obj.id+" ._content");
}
Apps.form.prototype.column = function(){
	var title = '显示栏目';
	var data = jQuery('._data_column').html();
	var html = Ahtml.tag('form',{"method":'post',"class":"_set_column"},data);
	this.show(title,html,{width:200,height:500});
}
Apps.form.prototype.column_chk = function(fields){
	var id = '.column-'+fields;
	var checked = jQuery(id+' input').attr('checked');
	if(checked=='checked'){
		jQuery(id+' span').attr('class','-brown');
		jQuery(id+' span').html('×');
		jQuery(id+' input').removeAttr('checked','checked');
	}else{
		jQuery(id+' span').attr('class','-green');
		jQuery(id+' span').html('√');
		jQuery(id+' input').attr('checked','checked');
	}
}
//--处理单个field的html
//内调函数
Apps.form.prototype.col_html = function(field,id,obj,val){
	var option = '',check;
	var column = this.columns;
	var data = column.form[field];
	data.name = 'save['+field+']';
	data.title = column.comment[field];
	this.field = data.field = field;
	var value,dlcss=Object();
	if(id){
		if(val){
			value = val;
		}else{
			value = jQuery('#data-'+id+'-'+field+' span').text();
		}
		if(data.type == 'datetime'){
			value = data.value.replace(' ','T')+'Z';
		}
	}else{
		if(val) value = val;
	}
	if(data.type=='textarea'){
		option = Ahtml.tag('textarea',data)
	}else if(data.type=='key'){
		dlcss['class']='dis_none';
		data['class'] = 'dis_none';
		data['key'] = 'key';
		if(id){option = id+Ahtml.tag('input',data);}
	}else if(data.type=='hidden'){
		dlcss['class']='dis_none';
		data.type = 'hidden';
		option = Ahtml.tag('input',data);
	}else{
		option = Ahtml.tag('input',data)
	}
	if(column['enum'] && column['enum'][field]){
		option = this.enums(field,data);
	}
	try{check = column.check[field];}catch(e){}
	var strchk='';
	if(typeof check=='object' && check.type.length>0 && Acan.base.in_array('require',check.type.split(' '))){
		strchk = '<span class="-red">*</span>';
	}
	var html = Ahtml.tag('dt',dlcss,strchk+column.comment[field])+Ahtml.tag('dd',dlcss,option);
	if(obj){
		obj.append(html);
		if(data.type=='radio'){
			obj.find('input[name="'+data.name+'"][value="'+value+'"]').attr("checked","checked");
		}else if(data.type=='textarea'){
			obj.find('textarea[name="'+data.name+'"]').val(value);
		}else if(data.type=='image'){
			obj.find('input[name="'+data.name+'"]').attr('src',value);
		}else if(data.type=='key'){
			if(id){obj.find('input[name="'+data.name+'"]').val(id);}
		}else if(data.type=='select'){
			if(id){obj.find('select[name="'+data.name+'"]').val(value);}
		}else if(data.type=='checkbox'){
			if(id){obj.find('input[name="'+data.name+'"][value="'+value+'"]').attr("checked","checked");}
		}else{
			obj.find('input[name="'+data.name+'"]').val(value);
		}
	}
	if(data.ready){
		if(data.ready.substr(0,4)=='this'){
			setTimeout(data.ready.replace('this',this.objname),1);
		}else{
			setTimeout(data.ready,100);
		}
	}
	delete data.value;
	return html;
}
//内部函数
Apps.form.prototype.enums = function(field,data){
	var value = data.value;
	var column = this.columns;
	if(!Acan.base.in_array(data.type,['checkbox','select','radio'])){
		data.type = 'radio';
	}
	delete data.size;delete data.value;
	if(data.type=='checkbox'){
		var html = Acan.html.checkbox(data,column['enum'][field]);
	}
	if(data.type=='select'){
		var html = Acan.html.select(data,column['enum'][field]);
	}else{
		var html = Acan.html.inputs(data,column['enum'][field],value);
	}
	if(data.type=='checkbox'){
		data.value = Acan.base.obj_json(value);
	}else{
		data.value = value;
	}
	return html;
}
Apps.form.prototype.add = function(id,title,aclass,vals){
	this.vals = vals;
	var titles= '添加';
	var model = Object();
	var column = this.columns;
	if(id){
		titles= '保存';
		if(typeof(this.url.info)=='string'){
			jQuery.ajax({
				async : false,
				type:"GET",url:this.url.info+id,
				beforeSend: function(){Acan.alert('开始请求');},
				ajaxSend: function(){Acan.alert('发送请求');},
				success: function(data){
					model = data;
				}
			});
			Acan.alert()
		}
	}
	if(!title){title = titles;}
	var css = {width:320,height:500};
	try{if(this.css.add){css=this.css.add;}
	}catch(e){}
	var html = Ahtml.tag('form',{method:"post",onsubmit:this.objname+".save(this);return false;",id:"column-ajax-form"},
		Ahtml.tag('div',{"class":"_column-form"},Ahtml.tag('dl',{"class":"-dl"}))+
		Ahtml.tag('input',{type:"submit","class":"_btn",value:titles})
	);
	var show = this.show(title,html,css);
	if(aclass) show.addClass(aclass);
	for(field in column.form){
		var val = model[field];
		//if(column.form[field].type=='hidden'){continue;}//如果为隐藏表单不编辑
		if(typeof(vals)=='object' && vals[field]){
			val = vals[field];
		}
		this.col_html(field,id,show.find('.-dl'),val);
	}
	jQuery('.acan_win form input[type!="hidden"]:first').focus();
	Acan.base.win_position();
}
//Aclass_list 调用
Apps.form.prototype.edit = function(obj){
	var arr = obj.id.split('-');
	var id = arr[1];
	var field = arr[2];
	var column = this.columns;
	if(typeof(column.form[field])!='object'){return;}//如果为没有type属性不编辑
	if(column.form[field].type=='hidden'){return;}//如果为隐藏表单不编辑
	var title= column.comment[field];
	var vals = Object();
	if(id){
		vals[field] = jQuery('#data-'+id+'-'+field+' span').text();
	}
	var html = Ahtml.tag('form',{method:"post",onsubmit:this.objname+".save(this);return false;",id:"column-ajax-form","class":"_column-form"},
		Ahtml.tag('dl',{'class':'-dl'})+
		Ahtml.tag('input',{type:"hidden",name:"save["+column.key+"]","key":"key",value:id})+
		Ahtml.tag('input',{type:"submit","class":"_btn",value:"提交"})
	);
	var show = this.show(title,html,{width:500,height:"auto"});
	this.col_html(field,id,show.find('.-dl'));
	if(jQuery('.acan_win form input:first').length>0)
		jQuery('.acan_win form input:first').focus();
	Acan.base.win_position();
}
Apps.form.prototype.edit_ex = function(field,data){
	var column = this.columns;
	data.name = 'save['+field+']';
	data.title = column.comment[field];
	var html = Ahtml.tag("span",{"class":"-right"},this.enums(field,data));
	jQuery('input[name="save['+this.field+']"]:last').after(html);
}

//内调函数
Apps.form.prototype.save = function(obj){
	var column = this.columns;
	var obj = jQuery('#'+obj.id);
	var error = false,pattern,flags;
	var field,msg,rdata;
	obj.find('input').each(function(i){
		field = jQuery(this).attr('field');
		var val = jQuery(this).val();
		var title = jQuery(this).attr('title');
		var check,regexp;
		var ctitle='';
		try{check = column.check[field];regexp = column.regexp;ctitle = check.title;}catch(e){}
		if(val.length==0){
			if(typeof check=='object' && check.type.length>0 && Acan.base.in_array('require',check.type.split(' '))){
				msg = title+' 必须填写!';
				error = true;
				return false;
			}
		}else{
			if(typeof check=='object' && check.type.length>0 && Acan.base.in_array('number',check.type.split(' '))){
				if(!Acan.base.is_numeric(val)){
					msg = title+' 必须为数字!';
					error = true;
					return false;
				}
			}
			if(typeof(regexp)=='object' && typeof(regexp[field])=='object'){
				var r = val.match(regexp[field]);
				if(Acan.count(r)==0 || r[0]!=val){
					msg = title+'格式错误!'+ctitle;
					error = true;
					return false;
				}
			}
		}
	});
	if(error){
		Acan.alert(Ahtml.tag('span',{"class":"-red"},msg),1000);
		obj.find('input[name="save['+field+']"]').focus();
		return;
	}
	var data = obj.serialize();
	var drr = obj.serializeArray();
	obj.find('textarea').each(function(i){
		var form = jQuery(this).attr('form');
		var name = jQuery(this).attr('name');
		if(typeof(name)=='undefined') return;
		if(form) try{Acan.base.str_fun(form);}catch(e){}
		data += '&'+name+'='+jQuery(this).val();
	});
	var field_test = /save\[([a-zA-Z0-9_]+?)\](.*)/;
	var save = Object();
	for(var i in drr){
		if(field_test.test(drr[i].name)){
			var mrr = drr[i].name.match(field_test);
			var field = mrr[1];
			try{
				if(column.form[field].type=='datetime'){
					drr[i].value = drr[i].value.replace('T',' ').replace('Z','');
				}
			}catch(e){}
			if(mrr[2]=='[]'){
				if(!save[field]){save[field] = [];}
				save[field].push(drr[i].value);
			}else{
				save[field] = drr[i].value;
			}
			if(field == column.key){
				var key = drr[i].value;
			}
		}
	}
	jQuery.ajax({
		async : false,
		type:"POST",url:this.url.save,data:data,
		beforeSend: function(){Acan.alert('开始请求');},
		ajaxSend: function(){Acan.alert('发送请求');},
		success: function(data){
			rdata = data;
		}
	});
	if(typeof(rdata)=='object'){
		msg = rdata.msg;
		Acan.alert(decodeURI(rdata.msg),1500);
		if(rdata.status==0){
			if(!key){setTimeout('Acan.url.refresh()',1000);}
		}
		return;
	}else if(rdata==1){
		msg = '更新成功';
		this.save_set(save,key);
		Acan.close(this.Did);
	}else if(rdata==0){
		msg = '没有更新';
	}else{msg = '更新失败:'+rdata;}
	Acan.alert(msg,1000);
	if(!key){setTimeout('Acan.url.refresh()',1000);}
}
//内调函数
Apps.form.prototype.save_set = function(save,key){
	var column = this.columns;
	var type = '';
	try{type = column.form[field].type;}catch(e){}
	for(field in save){
		if(field=='undefined'){continue;}
		if(type=='hidden'){continue;}//如果为隐藏表单不编辑
		if(column['enum'] && column['enum'][field]){
			if(type=='checkbox'){
				for(var i in save[field]){
					if(str){
						str += ','+column['enum'][field][save[field][i]]
					}else{
						var str = column['enum'][field][save[field][i]]
					}
				}
				save[field]=Acan.base.obj_json(save[field]);
			}else{
				var str = column['enum'][field][save[field]];
			}
			jQuery('#data-'+key+'-'+field+' a').text(str);
		}
		jQuery('#data-'+key+'-'+field+' span').text(save[field]);
		try{
			if(typeof(model)=='object' && typeof(model[key])=='object' && model[key][field]){
				model[key][field] = save[field];
			}
		}catch(e){
		}
	}
}
Apps.form.prototype.del = function(id){
	var url = Aurl.Amodr+'-del-'+id;
	jQuery.ajax({
		type:"POST",url:url,data:{"key":id},
		beforeSend: function(){Acan.alert('开始请求');},
		ajaxSend: function(){Acan.alert('发送请求');},
		success: function(data){
			Acan.alert(data,1000);
			setTimeout('Acan.url.refresh()',1000);
		}
	})
}

Apps.form.readys = function(){
	var id = jQuery('.model_form_id').val();
	if(id == ''){
		var btn_text = '添加';
	}else{
		var btn_text = '更新';
	}
	var html = Acan.html.tag('tr',{},
		Acan.html.tag('td',{colspan:'10',align:'center'},
			Acan.html.tag('input',{type:'button',onclick:'Apps.form.ajax_save('+id+')',value:btn_text})
			+Acan.html.tag('input',{type:'button',onclick:'Acan.url.back()',value:'返回'})
		)//操作按钮
	)
	html = Acan.html.tag('table',{'class':'-table'},html);//操作按钮
	jQuery("#save_form").append(html);
}
Apps.form.ajax_save = function(id){
//	Acan.login.sys_auth();
	if(typeof(id) == 'undefined'){id = '';}
	var save = jQuery("#save_form").serialize();
	jQuery.ajax({type: "POST",url: Aurl.Amodr+"-save-"+id,data: save,
		beforeSend: function(){Acan.alert('开始请求');},
		ajaxSend: function(){Acan.alert('发送请求');},
		success: function(data){
			Acan.alert(data,1000);
		}
	})
}

Apps.cmd = function (){}
Apps.cmd.taskkill = function(pid,str){
	if(!confirm('确定要结束进程：'+jQuery("#_taskname-"+pid).text()+'吗?')){return;}
	var formdata;
	if(!isNaN(pid)){
		formdata = "&pid="+pid;
	}else{
		formdata = "&taskname="+pid;
	}
	var url = jQuery("#url_taskkill").val();
	if(str){formdata += "&str="+str;}
	jQuery.ajax({
		type: "POST",
		url: url,
		data: formdata,
		success: function(data){
			jQuery("#_tasks-"+pid).remove();
			Acan.alert(data,2000);
		}
	})
}
Apps.cmd.show = function(){
	var url = jQuery("#url_cmd_run").val();
	var cmd = jQuery("#cmd_val").val();
	Apps.cmd.run(cmd,url);
	return false;
}
Apps.cmd.run = function(cmd,url){
	jQuery("#cmd_val").val(cmd);
	if(!url) url = jQuery("#url_cmd_run").val();
	jQuery("#cmd_run_status").html('请求中...');
	jQuery("#cmd_run_show").html('');
	jQuery.ajax({
		type: "POST",
		url: url,
		data: "&cmd="+cmd,
		success: function(data){
			jQuery("#cmd_run_status").html('请求完成');
			jQuery("#cmd_run_show").html(data);
		}
	})
}
//分类联动菜单
/*数据格式
每级的属性
obj = {
	1:{'name':'she'},
	2:{'name':'shi'},
	3:{'name':'xian'}
}
每级的数据
data = {
	1:{'a':'选项a','b':'选项b'},
	2:{'a':{'a1':'选项a1','a2':'选项a2'},'b':{'b1':'选项b1','b2':'选项b2'}},
	3:{'a1':{'a11':'选项a11','a12':'选项a12'},'a2':{'a21':'选项a21','a22':'选项a22'}}
}
默认选择
vrr = {'a','a1'}
*/
Apps.sl = function(Did,objname,obj,data,vrr,fun){
	this.Did = Did;//定义
	this.objname = objname;
	if(obj){
		
		this.readys(obj,data,vrr,fun);
	}
}
Apps.sl.prototype = new Apps.sl();
Apps.sl.prototype.readys = function(obj,data,vrr,fun){
	if(!obj){return;}
	if(!vrr){ vrr = '';}
	if(!fun){ fun = '';}
	this.data = data;
	this.obj = obj;
	this.fun = fun;
	var html='',datas;
	for(var i in data){
		datas = data[i];
		break;
	}
	var show = jQuery(this.Did);
	for(var i in obj){
		var opt='',next='';
		if(vrr[i]){
			next = vrr[i];
		}
		for(var k in datas){
			if(next==''){next = k;}
			var ops = {'value':k};
			if(vrr[i]==k){ops.selected = 'selected';}
			opt += Ahtml.tag('option',ops,datas[k]);
		}
		obj[i].id = '_'+i;
		var ni = parseInt(i)+1;
		if(typeof(data[ni])=='object'){
			var datas = data[ni][next];
			//obj[i].onchange = 'Apps.sl.change(\''+Did+'\','+i+')';
		}else{
			//obj[i].onchange = fun;
		}
		//obj[i].fun = fun;
		show.append(Ahtml.tag('select',obj[i],opt));
		if(opt.length==0){
			show.find("#"+obj[i].id).hide()
		}
	}
	var objname = this.objname;
	jQuery(this.Did+' select').change( function(i) {
		var sid = parseInt(jQuery(this).attr('id').split('_')[1]);
		setTimeout(objname+".change("+sid+")",1);
	});
	return;
}
//联动选项有变更时
Apps.sl.prototype.change = function(id){
	var val = jQuery(this.Did+' select[id="_'+id+'"]').val();
	var ni = id+1;
	if(typeof(this.data[ni])!='object'){if(this.fun){setTimeout(this.fun,1);} return;}//执行自定义函数
	var datas = this.data[ni][val];
	var opt='',first='';
	for(var k in datas){
		if(first==''){first=k;}
		var ops = {'value':k};
		opt += Ahtml.tag('option',ops,datas[k]);
	}
	if(opt.length>0){
		jQuery(this.Did+' select[id="_'+ni+'"]').show();
	}else{
		jQuery(this.Did+' select[id="_'+ni+'"]').hide();
	}
	var nextobj = jQuery(this.Did+' select[id="_'+ni+'"]');
	nextobj.html(opt);
	//上级有变更，则隐藏下下级
	var onum = Acan.count(this.obj);
	if(onum-id > 0){
		for (var i=id+2; i <= onum; i++) {
			jQuery(this.Did+' select[id="_'+i+'"]').hide();
		}
	}
	if(this.fun){setTimeout(this.fun,1);}//执行自定义函数
	jQuery(this.Did+' select[id="_'+ni+'"]'+' option[value="'+first+'"]').attr('selected','selected');
}
//获取联动菜单的值，返回数组 可以指定获取的等级
Apps.sl.prototype.value = function(id){
	if(!id){
		id=Acan.count(this.obj);
	}
	var val = {};
	for (var i=0; i <= id; i++) {
		if(jQuery(this.Did+' select[id="_'+i+'"]').length>0){
			val[i] = jQuery(this.Did+' select[id="_'+i+'"]').val();
		}
	}
	return val;
}
//获取联动菜单的选项标题
Apps.sl.prototype.title = function(id){
	if(!id){
		id=Acan.count(this.obj);
	}
	var title = {};
	for (var i=0; i <= id; i++) {
		if(jQuery(this.Did+' select[id="_'+i+'"]').length>0)
			title[i] = jQuery(this.Did+' select[id="_'+i+'"]'+' option:selected').text();
	}
	return title;
}



//分类联动菜单
Apps.cg = function(obj){	return Apps.cg.anew(obj);}
Apps.cg.anew = function(obj){this.obj=obj;	return this;}
Apps.cg.readys = function(obj){
	if(this.obj){
		var obj = this.obj;
	}
	var childs_id = obj.id+'_childs';//子级菜单大span id
	var childs_obj = jQuery("#"+childs_id);//子级菜单大span对象
	var html_c_1 = Acan.html.tag('span',{id:obj.id+"_1_child"});//二级菜单span标签
	if(childs_obj.attr('id')){
		childs_obj.html(html_c_1);//选择一级时重置下级所有
	}else{
		jQuery("#"+obj.id).attr('onchange','Acg.select('+obj.objname+')');
		jQuery("#"+obj.id).after(Acan.html.tag('span',{id:childs_id}));
		childs_obj.append(html_c_1);
		Apps.cg.select(obj);
	}
} 
Apps.cg.ready_child = function(obj,child,cval,onchange){
	var child_id = obj.id+'_'+child+'_child';
	if(jQuery("#"+child_id).attr('id')){return;}
	var child_span = Object();
	jQuery("#"+obj.id+'_'+(child-1)+'_child').after(Acan.html.tag('span',{'id':child_id}));
	if(onchange==1)	Apps.cg.select(obj,child,cval);
}
/*
obj : 菜单json数据
child : 菜单子级别(0为一级,1为二级,2为三级)
cval : 当前父对象的子菜单key
*/
Apps.cg.select = function(obj,child,pkey,onchange){
	var cg_id = obj.id;
	if(!onchange){var onchange = 1;}//非用户操作进入,用户操作阻止其子选择
	if(!child){Apps.cg.readys(obj); var child = 1;}//默认为二级
	var cg_id_c = obj.id+'_'+child;
	var cg_name = obj.name;
	var cg_obj = obj.cg;
	cg_obj.child_val = 2;
	var cg_objname = obj.objname;
	var key = jQuery('#'+cg_id).val();
	var keyval = key;
	//三级以上联动菜单
	if(child > 1){
		var cg_id = obj.id+'_'+child;
		Apps.cg.ready_child(obj,child,pkey,onchange);
		key = jQuery('#'+obj.id+'_'+(child-1)).val();
		keyval = pkey+'_'+key;
		cg_obj = Apps.cg.child_obj(obj.cg,pkey);
		if(!cg_obj)
			return;//无子对象直接返回
	}
	var child_obj = '';
	if(typeof(cg_obj.child)=='object'){
		child_obj = cg_obj.child[key];
	}
	var child_tag = Object();
	child_tag.name = cg_name;
	child_tag.id = cg_id_c;
	if(typeof(child_obj)=='object' && child_obj.child){
		if(isNaN(keyval)) var h_kval = "'"+keyval+"'";else var h_kval=keyval;
		child_tag.onchange = "Acg.select("+cg_objname+","+cg_obj.child_val+","+h_kval+",2)";
	}
	if(child_obj){
		var html = ' -> '+Acan.html.select(child_tag,child_obj.arr,child_obj.val);
	}else{
		var html = '';
	}
	jQuery("#"+cg_id_c+"_child").html(html);
	if(child_obj && onchange==1){
		Apps.cg.select(obj,child+1,keyval);
	}
}
//返回子对象
Apps.cg.child_obj = function(obj,pkey){
	var c_obj = Object();
	if(!isNaN(pkey)){
		c_obj = obj.child[pkey];
		c_obj.child_val = 3;
	}else{
		var prr = pkey.split('_');
		c_obj = obj;
		for (var i=0; i < prr.length; i++) {
			c_obj = c_obj.child[prr[i]];
		}
		if(prr.length > 1){
			c_obj.child_val = prr.length+2;
		}
	}
	return c_obj;
}




Apps.user = function(obj){
	this.obj=obj;
}
Apps.user.prototype = new Apps.user();
Apps.user.prototype.ready = function(){
}
Apps.user.prototype.save = function(){
	
}

Apps.test = function(obj){this.obj=obj;}
Apps.test.prototype = new Apps.test();
Apps.test.prototype.ready = function(){
	this.cc = this.obj.id+this.obj.set;
}

Apps.test.prototype.get = function(){
	this.ready();
	//alert(this.cc);
}
jQuery(document).ready(function(){
	Apps.form.readys();
	Apps.header.ready();
	var Atest = new Apps.test({'id':'123','set':'name'});
	var Atest2 = new Apps.test({'id':'1234','set':'name2'});
	Atest.get();
	Atest2.get();
	
});

